<template>
    <div class="nav">
        <ul>
            <li v-for="item,index in MainList" :key="item.id" :class="{hover:index == tabindex}" @mouseover="tabindex = index"
                @mouseout="tabindex = -1">
                <a href="javascript:;">{{item.name}}</a>
                <a href="javascript:;">{{item.children[0].name}}</a>
                <a href="javascript:;" v-if="item.children[1]">{{item.children[1].name}}</a>
                <div class="navList" v-if="index==tabindex">
                    <h4>分类推荐<span>根据您的购买或者浏览记录推荐</span></h4>
                    <div class="list">
                        <dl v-for="MainListitem in item.goods">
                            <dt><img :src="MainListitem.picture" alt=""></dt>
                            <dd>
                                <p>{{MainListitem.name}}</p>
                                <p>{{MainListitem.desc}}</p>
                                <p>￥<span>{{MainListitem.price}}</span></p>
                            </dd>
                        </dl>
                    </div>
                </div>
            </li>
            <li :class="{hover:str == '品牌'}" @mouseover="str = '品牌'" @mouseout="str = ''">
                <a href="javascript:;">品牌</a>
                <a href="javascript:;">品牌推荐</a>
                <div class="navList" v-if="str == '品牌'">
                    <h4>品牌推荐<span>根据您的购买或者浏览记录推荐</span></h4>
                    <div class="list">
                        <dl v-for="item in brandList">
                            <dt><img :src="item.picture" alt=""></dt>
                            <dd>
                                <p>{{item.place}}</p>
                                <p>{{item.name}}</p>
                                <p>{{item.desc}}</p>
                            </dd>
                        </dl>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</template>

<script>

export default {
    data() {
        return {
            tabindex:-1,
            str:'',
            brandList:[]
        }
    },
    props:['MainList'],
    methods: {
        
    },
    mounted() {
        this.axios.get('https://apipc-xiaotuxian-front.itheima.net/home/brand?limit=6').then((res)=>{
            if(res.data.msg == '操作成功'){
                this.brandList = res.data.result
            }
        })
        
    },
}
</script>

<style lang="scss" scoped>
.nav {
    position: absolute;

    ul {
        position: relative;
        background: rgba(0, 0, 0, .8);
        width: 250px;
        height: 100%;
        z-index: 100;
        .hover{
            background: #27ba9b;
        }

        li {
            text-align: left;
            padding-left: 40px;
            height: 50px;
            line-height: 50px;

            a {
                margin-right: 4px;
                color: #fff;
                font-size: 14px;

                &:nth-of-type(1) {
                    font-size: 16px;
                }
            }
        }
    }

}
.navList {
        width: 990px;
        height: 500px;
        background: hsla(0, 0%, 100%, .8);
        position: absolute;
        left: 250px;
        top: 0;
        padding: 0 15px;

        h4 {
            font-size: 20px;
            font-weight: 400;
            line-height: 80px;

            span {
                font-size: 16px;
                color: #666;
                margin-left: 10px;
            }
        }

        .list {
            display: flex;
            flex-wrap: wrap;

            dl {
                width: 300px;
                height: 120px;
                margin-right: 15px;
                margin-bottom: 15px;
                border: 1px solid #eee;
                border-radius: 4px;
                background: #fff;
                display: flex;
                padding: 10px;

                dt {
                    width: 95px;
                    height: 95px;
                    margin-right: 10px;

                    img {
                        width: 100%;
                    }
                }

                dd {
                    p {
                        line-height: 1.5em;

                        &:nth-of-type(1) {
                            font-size: 16px !important;
                            color: #666;
                            display: -webkit-box;
                            -webkit-box-orient: vertical;
                            -webkit-line-clamp: 2;
                            width: 180px;
                        }

                        &:nth-of-type(2) {
                            color: #999;
                            white-space: nowrap;
                            text-overflow: ellipsis;
                            overflow: hidden;
                            width: 180px;
                        }

                        &:nth-of-type(3) {
                            font-size: 16px !important;
                            color: #cf4444;

                            span {
                                font-size: 22px;
                            }
                        }
                    }
                }
            }
        }
    }
</style>